package com.spark.tags;

import java.util.Map;

import com.spark.core.SparkContext;
import com.spark.core.XMap;

public class TextArea extends Field {

	private static final String DEFAULT_CLASS = "s_ta";
	
	public static final String DEFAULT_TEMPLATES = "textArea.ftl";
	
	protected int getDefaultWidth(){
		return 150;
	}
	
	protected int getDefaultHeight(){
		return 50;
	}
	
	public String getTemplate(){
		return DEFAULT_TEMPLATES;
	}
	
	protected String getDefaultClass(XMap view,SparkContext context){
		String wrapClass = super.getDefaultClass(view, context);
		StringBuilder sb = new StringBuilder();
		sb.append(wrapClass);
		if(!"".equals(wrapClass.trim()))sb.append(" ");
		sb.append(DEFAULT_CLASS);
		
		return sb.toString();
	}
	
	@SuppressWarnings("unchecked")
	protected String build(SparkContext context){
		Map map = context.getMap();
		StringBuilder sb = new StringBuilder();
		sb.append("<textarea class=\"").append(get(map,"className")).append("\" stype=\"input\" style=\"width:").append(get(map,"width")).append("px;height:").append(get(map,"height")).append("px;").append(get(map,"style")).append("\" id=\"").append(get(map,"id")).append("\">").append(get(map,"value")).append("</textarea>\r");
		sb.append("<script>\r");
		sb.append("	new Spark.TextArea(").append(get(map,"config")).append(");\r");
		sb.append("</script>\r");
		return sb.toString();
	}
}
